//! 用户模块
const express = require('express');
//!引入数据库连接池
const pool = require('../pool');
//!  1.创建路由器
const router = express.Router();
//!  2.响应
//! 通过关键字搜索菜谱
router.get('/',(req,res)=>{
    let keyword= req.query.keyword;
    console.log(keyword);
    let sql = 'select b.bid,b.uid,rate,title,`describe`,pic,cid,create_time,u.uname ,u.upic from cook_books AS b INNER JOIN cook_users as u ON b.uid=u.uid where title LIKE ?'

    // pool.query(`select b.bid,b.uid,rate,title,describe,pic,cid,create_time,u.uname ,u.upic from cook_books AS b INNER JOIN cook_users as u ON b.uid=u.uid where title LIKE '%${keyword}%';`,(err,result)=>{
    // pool.query('select b.bid,b.uid,rate,title,`describe`,pic,cid,create_time,u.uname ,u.upic from cook_books AS b INNER JOIN cook_users as u ON b.uid=u.uid where title LIKE '%${keyword}%';',(err,result)=>{
    pool.query(sql,[`%${keyword}%`],(err,result)=>{
        console.log(result);
        if(err) throw err;
        if(result.length==0){
            res.send({code:200,msg:'菜谱不存在'});
        }else{
            res.send({code:200,msg:'查询成功',data:result});
        }
    });
});
//! 3.导出路由器
module.exports = router;




